package com.guohong.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.guohong.common.RestResult;
import com.guohong.constant.ResponseCodeConstant;
import com.guohong.exception.ServiceException;
import com.guohong.service.PermissionService;
import com.guohong.vo.PermissionVo;

@RestController
@RequestMapping("/permi")
public class PermissionController {
	private final Logger logger = LoggerFactory.getLogger(PermissionController.class);

	@Autowired
	private PermissionService permissionService;

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ResponseBody
	public RestResult<Integer> permiAdd(@RequestBody PermissionVo permissionVo) {
		RestResult<Integer> result = new RestResult<>();

		try {
			Integer count = permissionService.insert(permissionVo);
			result.setCode(ResponseCodeConstant.SUCCESS);
			result.setData(count);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setCode(e.getCode());
			result.setMsg(e.getMessage());

		} catch (Exception e) {
			e.printStackTrace();

			result.setCode(ResponseCodeConstant.FAILED);
			result.setMsg("系统内部错误");
		}

		return result;
	}

}
